package com.sdp.right.db.sys_menu.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.core.bizc.threadLocal.ContextManager;
import com.sdp.core.bizc.utils.CoreConstantsEnum;
import com.sdp.right.db.sys_menu.mapper.SysMenuMapper;
import com.sdp.right.db.sys_menu.service.ISysMenuService;
import com.sdp.right.db.sys_role.service.ISysRoleService;
import com.sdp.right.db.sys_role_menu.service.impl.SysRoleMenuServiceImpl;
import com.sdp.right.db.sys_role_person.service.ISysRolePersonService;
import com.sdp.right.entity.SysMenu;
import com.sdp.right.entity.SysSystem;
import com.sdp.right.service.RemoveSystemService;
import com.sdp.right.utils.RightConstants;
import com.sdp.right.view.SysRoleMenuView;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2023-10-11
 */
@Service
@DS(value="right")
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService,RemoveSystemService {
	
	@Autowired
	private ISysRolePersonService iSysRolePersonService;
	
	@Autowired
	private SysRoleMenuServiceImpl sysRoleMenuServiceImpl;
	
	@Autowired
	private ISysRoleService iSysRoleService;
	
	public JSONObject queryMenuTreeSelect(String systemNo){
		List<Object> treeList = new ArrayList<Object>();
		List<SysMenu> menuList = querySysMenu(systemNo);
		List<SysMenu> rootList = new ArrayList<SysMenu>();
		List<String> menuKeys = new ArrayList<String>();
		JSONObject menuTree =  new JSONObject();
		if(menuList!=null && menuList.size()>0) {
			for(SysMenu menu : menuList) {
				menuKeys.add(menu.getKeyId());
				if(StringUtils.isEmpty(menu.getParentId()) || RightConstants.否.getCode().equals(menu.getParentId())) {
					rootList.add(menu);
				}
			}
		}
		
		if(rootList!=null && rootList.size()>0) {
			
			for(int i=0;i<rootList.size();i++) {
				JSONObject parentObj = new JSONObject();
				parentObj.put("title", rootList.get(i).getMenuTitle());
				parentObj.put("value", rootList.get(i).getKeyId());
				parentObj.put("key",rootList.get(i).getKeyId());
				treeList.add(parentObj);
				getChildMenuTreeSelect(parentObj, menuList);
			}
		}
		menuTree.put("treeKeys", menuKeys);
		menuTree.put("treeData", treeList);
		return menuTree;
		
	}
	
	@SuppressWarnings({ "unchecked" })
	private void getChildMenuTreeSelect(JSONObject parentObj,List<SysMenu> menuList) {
		List<Object> childList = new ArrayList<Object>();
	
		for(int j=0;j<menuList.size();j++) {
			if(!StringUtils.isEmpty(menuList.get(j).getParentId()) && parentObj.getString("key").equals(menuList.get(j).getParentId())) {
				
				if(parentObj.get("children")==null) {
					parentObj.put("children", childList);
				}else {
					childList = (List<Object>) parentObj.get("children");
				}
				
				JSONObject childObj = new JSONObject();
				childObj.put("title", menuList.get(j).getMenuTitle());
				childObj.put("value", menuList.get(j).getKeyId());
				childObj.put("key",menuList.get(j).getKeyId());
				childList.add(childObj);
				getChildMenuTreeSelect(childObj, menuList);
			}
			
		}
	}

	@Override
	public List<JSONObject> queryMenuTableTree(String systemNo) {
		List<JSONObject> menuTableTreeList = new ArrayList<JSONObject>();
		List<SysMenu> menuList = querySysMenu(systemNo);
		if(menuList==null || menuList.size()==0) {
			return menuTableTreeList;
		}
		
		List<SysMenu> rootList = new ArrayList<SysMenu>();
		for(SysMenu menu : menuList) {
			if(StringUtils.isEmpty(menu.getParentId()) || RightConstants.否.getCode().equals(menu.getParentId())) {
				rootList.add(menu);
			}
		}
		if(rootList==null || rootList.size()==0) {
			return menuTableTreeList;
		}
		JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
		JSONObject parentObj =null;
		for(int i=0;i<rootList.size();i++) {
			parentObj = JSON.parseObject(JSON.toJSONStringWithDateFormat(rootList.get(i), "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue,SerializerFeature.WriteDateUseDateFormat));
			menuTableTreeList.add(parentObj);
			getChildMenu(parentObj, menuList);
		}
		
		return menuTableTreeList;
	}
	
	@SuppressWarnings("unchecked")
	private void getChildMenu(JSONObject parentObj,List<SysMenu> menuList) {
		List<Object> childList = new ArrayList<Object>();
		for(int j=0;j<menuList.size();j++) {
			if(!StringUtils.isEmpty(menuList.get(j).getParentId()) && parentObj.getString("keyId").equals(menuList.get(j).getParentId())) {
				
				if(parentObj.get("children")==null) {
					parentObj.put("children", childList);
				}else {
					childList = (List<Object>) parentObj.get("children");
				}
				JSONObject childObj = JSON.parseObject(JSON.toJSONStringWithDateFormat(menuList.get(j),"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue,SerializerFeature.WriteDateUseDateFormat).toString());
				childList.add(childObj);
				getChildMenu(childObj, menuList);
			}
			
		}
	}

	@Override
	public List<SysMenu> queryAllSysMenu() {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.orderByAsc(SysMenu::getSortNo);
		return list(queryWrapper);
	}

	@Override
	public List<SysMenu> querySysMenu(String systemNo) {
		//查看当前登录人是否为开发者
		String loginAccountNo = ContextManager.getContextData(CoreConstantsEnum.token中账号的属性名.getCode()).toString();
		List<String> roleNos = iSysRolePersonService.queryRoleNos(loginAccountNo);
		boolean isDeveloper = iSysRoleService.isDeveloper(roleNos);
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		if(!StringUtils.isEmpty(systemNo)) {
			queryWrapper.eq(SysMenu::getSystemNo, systemNo);
		}
		//如果不是开发人员
		if(!isDeveloper) {
			queryWrapper.and(wrapper->wrapper.ne(SysMenu::getIsDevelop, RightConstants.是.getCode()).or().isNull(SysMenu::getIsDevelop));
		}
		queryWrapper.orderByAsc(SysMenu::getSortNo);
		return list(queryWrapper);
	}

	@Override
	public List<SysMenu> querySysMenu(String systemNo, String isUse) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenu::getSystemNo, systemNo);
		queryWrapper.eq(SysMenu::getIsUse, isUse);
		queryWrapper.orderByAsc(SysMenu::getSortNo);
		return list(queryWrapper);
	}

	@Override
	public String queryParentMenuLevel(String parentMenuId) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenu::getKeyId, parentMenuId);
		SysMenu sysMenu = getOne(queryWrapper);
		if(sysMenu==null || StringUtils.isEmpty(sysMenu.getParentLevel())) {
			return "";
		}
		return sysMenu.getParentLevel();
	}

	@Override
	public int queryChildMenuCount(String menuId) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.like(SysMenu::getParentLevel, "["+menuId+"]");
		return count(queryWrapper);
	}

	@Override
	public List<JSONObject> createRouterTree(boolean isRight, String accountNo, String systemNo) {
		List<JSONObject> routerTreeList = new ArrayList<JSONObject>();
		List<SysMenu> menuList = new ArrayList<>();
		if(isRight) {
			menuList = queryPermissionsSysMenu(accountNo, systemNo);
		}else {
			menuList = querySysMenu(systemNo,RightConstants.是.getCode());
		}
		
		if(menuList==null || menuList.size()==0) {
			return routerTreeList;
		}
		
		List<SysMenu> rootList = new ArrayList<SysMenu>();
		for(SysMenu menu : menuList) {
			if(StringUtils.isEmpty(menu.getParentId()) || RightConstants.否.getCode().equals(menu.getParentId())) {
				rootList.add(menu);
			}
		}
		
		if(rootList==null || rootList.size()==0) {
			return routerTreeList;
		}
		
		for(int i=0;i<rootList.size();i++) {
			JSONObject parentObj = new JSONObject();
			parentObj.put("path", StringUtils.isEmpty(rootList.get(i).getMenuPath())?"/view"+rootList.get(i).getKeyId():rootList.get(i).getMenuPath());
			parentObj.put("name", RightConstants.菜单路由名前缀.getCode()+rootList.get(i).getKeyId());
			parentObj.put("component",StringUtils.isEmpty(rootList.get(i).getMenuComponent())?"RouteView":rootList.get(i).getMenuComponent());
			JSONObject meta = new JSONObject();
			meta.put("icon", rootList.get(i).getMenuIcon());
			meta.put("title", rootList.get(i).getMenuTitle());
			meta.put("keyId", rootList.get(i).getKeyId());
			meta.put("pageId", rootList.get(i).getPageId());
			meta.put("extLink", rootList.get(i).getExtLink());
			meta.put("isNewWin", rootList.get(i).getIsNewWin());
			meta.put("sysMenu", rootList.get(i));
			meta.put("isHide", rootList.get(i).getIsHide());
			parentObj.put("meta", meta);
			routerTreeList.add(parentObj);
			getChildRouter(parentObj, menuList);
		}
		
		
		return routerTreeList;
	}

	@SuppressWarnings("unchecked")
	private void getChildRouter(JSONObject parentObj,List<SysMenu> menuList) {
		List<Object> childList = new ArrayList<Object>();
	
		for(int j=0;j<menuList.size();j++) {
			if(!StringUtils.isEmpty(menuList.get(j).getParentId()) && parentObj.getJSONObject("meta").getString("keyId").equals(menuList.get(j).getParentId())) {
				
				if(parentObj.get("children")==null) {
					parentObj.put("children", childList);
				}else {
					childList = (List<Object>) parentObj.get("children");
				}
				
				JSONObject childObj = new JSONObject();
				childObj.put("path", StringUtils.isEmpty(menuList.get(j).getMenuPath())?"/view"+menuList.get(j).getKeyId():menuList.get(j).getMenuPath());
				childObj.put("name", RightConstants.菜单路由名前缀.getCode()+menuList.get(j).getKeyId());
				childObj.put("component",StringUtils.isEmpty(menuList.get(j).getMenuComponent())?"RouteView":menuList.get(j).getMenuComponent());
				JSONObject meta = new JSONObject();
				meta.put("icon", menuList.get(j).getMenuIcon());
				meta.put("title", menuList.get(j).getMenuTitle());
				meta.put("keyId", menuList.get(j).getKeyId());
				meta.put("pageId", menuList.get(j).getPageId());
				meta.put("extLink", menuList.get(j).getExtLink());
				meta.put("isNewWin", menuList.get(j).getIsNewWin());
				meta.put("sysMenu", menuList.get(j));
				meta.put("isHide", menuList.get(j).getIsHide());
				childObj.put("meta", meta);
				
				childList.add(childObj);
				getChildRouter(childObj, menuList);
			}
			
		}
	}
	
	@Override
	public List<SysMenu> queryPermissionsSysMenu(String accountNo, String systemNo) {
		List<SysMenu> menuList = new ArrayList<>();
		
		//根据账号获取所属角色
		List<String> roleNos = iSysRolePersonService.queryRoleNos(accountNo);
		if(roleNos==null || roleNos.size()==0) {
			return menuList;
		}
		
		//获取角色对应的菜单
		QueryWrapper<SysRoleMenuView> sysRoleMenuViewQuery = new QueryWrapper<>();
		sysRoleMenuViewQuery.in("b.role_no", roleNos);
		sysRoleMenuViewQuery.eq("a.system_no", systemNo);
		
		List<SysRoleMenuView> roleMenuViewList = sysRoleMenuServiceImpl.viewList(sysRoleMenuViewQuery,null);
		if(roleMenuViewList==null || roleMenuViewList.size()==0) {
			return menuList;
		}
		
		//获得菜单编号信息
		List<String> menuNoList = new ArrayList<>();
		//得到这些菜单的父层级信息 
		List<String> menuParentNoList = new ArrayList<>();
		for(SysRoleMenuView sysMenu : roleMenuViewList) {
			menuNoList.add(sysMenu.getKeyId());
			if(!StringUtils.isEmpty(sysMenu.getParentLevel())) {
				menuParentNoList.addAll(Arrays.asList(sysMenu.getParentLevel().replaceAll("\\[", "").replaceAll("\\]", ",").split(",")));
			}
		}
		menuNoList.addAll(menuParentNoList.stream().distinct().collect(Collectors.toList()));
		menuList = querySysMenu(menuNoList, RightConstants.是.getCode());	
		return menuList;
	}

	@Override
	public List<SysMenu> querySysMenu(List<String> menuNoList) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(SysMenu::getKeyId, menuNoList);
		queryWrapper.orderByAsc(SysMenu::getSortNo);
		return list(queryWrapper);
	}

	@Override
	public List<SysMenu> querySysMenu(List<String> menuNoList, String isUse) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(SysMenu::getKeyId, menuNoList);
		queryWrapper.eq(SysMenu::getIsUse, isUse);
		queryWrapper.orderByAsc(SysMenu::getSortNo);
		return list(queryWrapper);
	}

	@Override
	public void removeBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysMenu::getSystemNo, systemNo);
		remove(queryWrapper);
		
	}

	@Override
	public void initSystemMenu(SysSystem sysSystem) {
		SysMenu menu = new SysMenu();
		menu.setMenuTitle("系统管理");
		menu.setSystemNo(sysSystem.getSystemNo());
		menu.setSortNo(1);
		menu.setMenuIcon("setting");
		menu.setIsUse(RightConstants.是.getCode());
		menu.setIsHide(RightConstants.否.getCode());
		menu.setIsDevelop(RightConstants.否.getCode());
		menu.setIsNewWin(RightConstants.否.getCode());
		save(menu);
		
		List<SysMenu> menus = new ArrayList<>();
		//菜单管理
		SysMenu menu1 = new SysMenu();
		menu1.setMenuTitle("菜单管理");
		menu1.setSystemNo(sysSystem.getSystemNo());
		menu1.setParentId(menu.getKeyId());
		menu1.setMenuPath("/system/menus/menuList");
		menu1.setMenuComponent("system/menus/menuList");
		menu1.setSortNo(10);
		menu1.setMenuIcon("ordered-list");
		menu1.setIsUse(RightConstants.是.getCode());
		menu1.setIsHide(RightConstants.否.getCode());
		menu1.setIsDevelop(RightConstants.是.getCode());
		menu1.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu1);
		
		//组织管理
		SysMenu menu2 = new SysMenu();
		menu2.setMenuTitle("组织管理");
		menu2.setSystemNo(sysSystem.getSystemNo());
		menu2.setParentId(menu.getKeyId());
		menu2.setMenuPath("/system/org/orgList");
		menu2.setMenuComponent("system/org/orgList");
		menu2.setSortNo(20);
		menu2.setMenuIcon("cluster");
		menu2.setIsUse(RightConstants.是.getCode());
		menu2.setIsHide(RightConstants.否.getCode());
		menu2.setIsDevelop(RightConstants.否.getCode());
		menu2.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu2);
		
		//角色管理
		SysMenu menu3 = new SysMenu();
		menu3.setMenuTitle("角色管理");
		menu3.setSystemNo(sysSystem.getSystemNo());
		menu3.setParentId(menu.getKeyId());
		menu3.setMenuPath("/system/role/roleList");
		menu3.setMenuComponent("system/role/roleList");
		menu3.setSortNo(30);
		menu3.setMenuIcon("solution");
		menu3.setIsUse(RightConstants.是.getCode());
		menu3.setIsHide(RightConstants.否.getCode());
		menu3.setIsDevelop(RightConstants.否.getCode());
		menu3.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu3);
		
		//数据字典
		SysMenu menu4 = new SysMenu();
		menu4.setMenuTitle("数据字典");
		menu4.setSystemNo(sysSystem.getSystemNo());
		menu4.setParentId(menu.getKeyId());
		menu4.setMenuPath("/system/dict/dictTab");
		menu4.setMenuComponent("system/dict/dictTab");
		menu4.setSortNo(40);
		menu4.setMenuIcon("solution");
		menu4.setIsUse(RightConstants.是.getCode());
		menu4.setIsHide(RightConstants.否.getCode());
		menu4.setIsDevelop(RightConstants.否.getCode());
		menu4.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu4);
		
		//数据导入导出
		SysMenu menu5 = new SysMenu();
		menu5.setMenuTitle("数据导入导出");
		menu5.setSystemNo(sysSystem.getSystemNo());
		menu5.setParentId(menu.getKeyId());
		menu5.setMenuPath("/system/importtemplate/templateList");
		menu5.setMenuComponent("system/importtemplate/templateList");
		menu5.setSortNo(50);
		menu5.setMenuIcon("pie-chart");
		menu5.setIsUse(RightConstants.是.getCode());
		menu5.setIsHide(RightConstants.否.getCode());
		menu5.setIsDevelop(RightConstants.是.getCode());
		menu5.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu5);
		
		//定时任务管理
		SysMenu menu6 = new SysMenu();
		menu6.setMenuTitle("定时任务管理");
		menu6.setSystemNo(sysSystem.getSystemNo());
		menu6.setParentId(menu.getKeyId());
		menu6.setMenuPath("/system/cron/cronIndex");
		menu6.setMenuComponent("system/cron/cronIndex");
		menu6.setSortNo(60);
		menu6.setMenuIcon("dashboard");
		menu6.setIsUse(RightConstants.是.getCode());
		menu6.setIsHide(RightConstants.否.getCode());
		menu6.setIsDevelop(RightConstants.是.getCode());
		menu6.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu6);
		
		
		//登录日志
		SysMenu menu8 = new SysMenu();
		menu8.setMenuTitle("登录日志");
		menu8.setSystemNo(sysSystem.getSystemNo());
		menu8.setParentId(menu.getKeyId());
		menu8.setMenuPath("/system/loginlog/loginLogList");
		menu8.setMenuComponent("system/loginlog/loginLogList");
		menu8.setSortNo(80);
		menu8.setMenuIcon("login");
		menu8.setIsUse(RightConstants.是.getCode());
		menu8.setIsHide(RightConstants.否.getCode());
		menu8.setIsDevelop(RightConstants.否.getCode());
		menu8.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu8);
		
		//操作日志
		SysMenu menu9 = new SysMenu();
		menu9.setMenuTitle("操作日志");
		menu9.setSystemNo(sysSystem.getSystemNo());
		menu9.setParentId(menu.getKeyId());
		menu9.setMenuPath("/system/operlog/logList");
		menu9.setMenuComponent("system/operlog/logList");
		menu9.setSortNo(90);
		menu9.setMenuIcon("highlight");
		menu9.setIsUse(RightConstants.是.getCode());
		menu9.setIsHide(RightConstants.否.getCode());
		menu9.setIsDevelop(RightConstants.否.getCode());
		menu9.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu9);
		
		//账号管理
		SysMenu menu10 = new SysMenu();
		menu10.setMenuTitle("账号管理");
		menu10.setSystemNo(sysSystem.getSystemNo());
		menu10.setParentId(menu.getKeyId());
		menu10.setMenuPath("/system/emp/empList");
		menu10.setMenuComponent("system/emp/empList");
		menu10.setSortNo(100);
		menu10.setMenuIcon("team");
		menu10.setIsUse(RightConstants.是.getCode());
		menu10.setIsHide(RightConstants.否.getCode());
		menu10.setIsDevelop(RightConstants.否.getCode());
		menu10.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu10);
		
		//参数管理
		SysMenu menu11 = new SysMenu();
		menu11.setMenuTitle("参数管理");
		menu11.setSystemNo(sysSystem.getSystemNo());
		menu11.setParentId(menu.getKeyId());
		menu11.setMenuPath("/system/config/sysConfigList");
		menu11.setMenuComponent("system/config/sysConfigList");
		menu11.setSortNo(110);
		menu11.setMenuIcon("deployment-unit");
		menu11.setIsUse(RightConstants.是.getCode());
		menu11.setIsHide(RightConstants.否.getCode());
		menu11.setIsDevelop(RightConstants.否.getCode());
		menu11.setParentLevel("["+menu.getKeyId()+"]");
		menus.add(menu11);
		
		//页面设计器
		SysMenu menu12 = new SysMenu();
		menu12.setMenuTitle("页面设计器");
		menu12.setSystemNo(sysSystem.getSystemNo());
		menu12.setParentId(menu.getKeyId());
		menu12.setMenuPath("/system/codeGenerator/pageList");
		menu12.setMenuComponent("system/codeGenerator/pageList");
		menu12.setSortNo(120);
		menu12.setMenuIcon("code");
		menu12.setIsUse(RightConstants.是.getCode());
		menu12.setIsHide(RightConstants.否.getCode());
		menu12.setIsDevelop(RightConstants.是.getCode());
		menu12.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu12);
		
		//实体信息
		SysMenu menu13 = new SysMenu();
		menu13.setMenuTitle("实体信息");
		menu13.setSystemNo(sysSystem.getSystemNo());
		menu13.setParentId(menu.getKeyId());
		menu13.setMenuPath("/system/entity/entityList");
		menu13.setMenuComponent("system/entity/entityList");
		menu13.setSortNo(130);
		menu13.setMenuIcon("table");
		menu13.setIsUse(RightConstants.是.getCode());
		menu13.setIsHide(RightConstants.否.getCode());
		menu13.setIsDevelop(RightConstants.是.getCode());
		menu13.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu13);
		
		//数据权限
		SysMenu menu14 = new SysMenu();
		menu14.setMenuTitle("数据权限");
		menu14.setSystemNo(sysSystem.getSystemNo());
		menu14.setParentId(menu.getKeyId());
		menu14.setMenuPath("/system/dr/drList");
		menu14.setMenuComponent("system/dr/drList");
		menu14.setSortNo(140);
		menu14.setMenuIcon("sliders");
		menu14.setIsUse(RightConstants.是.getCode());
		menu14.setIsHide(RightConstants.否.getCode());
		menu14.setIsDevelop(RightConstants.是.getCode());
		menu14.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu14);
		
		//流程管理
		SysMenu menu15 = new SysMenu();
		menu15.setMenuTitle("流程管理");
		menu15.setSystemNo(sysSystem.getSystemNo());
		menu15.setParentId(menu.getKeyId());
		menu15.setMenuPath("/system/flow/flowIndex");
		menu15.setMenuComponent("system/flow/flowIndex");
		menu15.setSortNo(150);
		menu15.setMenuIcon("fork");
		menu15.setIsUse(RightConstants.是.getCode());
		menu15.setIsHide(RightConstants.否.getCode());
		menu15.setIsDevelop(RightConstants.是.getCode());
		menu15.setParentLevel("["+menu.getKeyId()+"]");
		menu.setIsNewWin(RightConstants.否.getCode());
		menus.add(menu15);
		
		
		saveBatch(menus);
		
	}


}
